//
//  YSHistoryCell.m
//  Yueshi
//
//  Created by Northwan on 15/7/23.
//  Copyright (c) 2015年 悦食中国. All rights reserved.
//

#import "YSHistoryCell.h"

#define PromotionBtnHeight 25

@interface YSHistoryCell()
@property (strong, nonatomic)  UIImageView *iconView;
@property (strong, nonatomic)  UILabel *titleLabel;
@property (strong, nonatomic)  UILabel *subTitleLabel;
@property (strong, nonatomic)  UIButton *tagBtn;

@end

@implementation YSHistoryCell

+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"YSHistoryCell";
    YSHistoryCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[YSHistoryCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        UIImageView *iconView = [[UIImageView alloc]init];
        [iconView setFrame:CGRectMake(YSPublicXInset, 0, SCREENW-YSPublicXInset*2, (SCREENW-YSPublicXInset*2)/1.8)];
        [self addSubview:iconView];
        _iconView = iconView;
        
        //标签
        UIButton *tagBtn = [[UIButton alloc]init];
        [tagBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [tagBtn.titleLabel setFont:SYS_FONT(14)];
        [tagBtn setBackgroundImage:[UIImage resizedImage:@"bg_list_promotion"] forState:UIControlStateNormal];
        [tagBtn setFrame:CGRectMake(0, YSPublicXInset, 50,PromotionBtnHeight)];
        [tagBtn setHidden:YES];
        self.tagBtn = tagBtn;
        [iconView addSubview:tagBtn];
        
        UILabel *titleLabel = [[UILabel alloc]init];
        [titleLabel setFrame:CGRectMake(YSPublicXInset, CGRectGetMaxY(iconView.frame)+YSPublicXInset, SCREENW-YSPublicXInset*2, 17)];
        [titleLabel setFont:SYS_FONT(17)];
        [titleLabel setTextColor:HEXColor(@"#333333")];
        [self addSubview:titleLabel];
        _titleLabel = titleLabel;
        
     
        UILabel *subTitleLabel = [[UILabel alloc]init];
        [subTitleLabel setFrame:CGRectMake(YSPublicXInset, CGRectGetMaxY(titleLabel.frame)+6, SCREENW-YSPublicXInset*2, 14)];
        [subTitleLabel setFont:SYS_FONT(14)];
        [subTitleLabel setTextColor:HEXColor(@"#999490")];
        [self addSubview:subTitleLabel];
        _subTitleLabel = subTitleLabel;
    }
    return self;
}

-(void)setReviews:(YSReviews *)reviews{
    _reviews = reviews;
    [self.iconView setImageURLStr:reviews.imgList];
    [self.titleLabel setText:reviews.postName];
    [self.subTitleLabel setText:reviews.summary];
    
    if(reviews.labelName){
        [self.tagBtn setHidden:YES];
        [self.tagBtn setTitle:reviews.labelName forState:UIControlStateNormal];
        CGSize tagSize =   [reviews.labelName sizeWithFont:SYS_FONT(14)];
        [self.tagBtn setWidth:tagSize.width+YSPublicXInset*2];
    }else{
        [self.tagBtn setHidden:YES];
    }
}

@end
